/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package util;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import main.MainEdgeMonthly;
import main.MainMonthly;

/**
 *
 * @author Djordje
 */
public class StackFilesUtil {

//    static String path = "c:\\Users\\Djordje\\Dropbox\\eksperimenti\\GCRFdjole_final\\pctdata\\rain_non_missing\\";
    static int numberOfTimesteps = 4;
    static int numberOfPredictors = MainMonthly.numberOfPredictors;

    public static void stackTrainingAndTestingResults() throws FileNotFoundException, UnsupportedEncodingException, IOException {
        ArrayList<ArrayList<String>> files = new ArrayList<>();
        for (int pred = 0; pred < numberOfPredictors; pred++) {
            String pathToFile = MainMonthly.path + "\\podaci_ts_all_precitor_" + (pred + 1) + "_clusters.csv";
            PrintWriter writer = new PrintWriter(new FileWriter(pathToFile, true));
            System.out.println(pathToFile);

            BufferedReader br = new BufferedReader(new FileReader(MainMonthly.path + "\\podaci_ts_training_precitor_" + (pred + 1) + "_clusters.csv"));

            String line = br.readLine();
            while (line != null) {
                if (!line.equals("") && line != null) {
                    writer.println(line);
                    writer.flush();
                }
                line = br.readLine();
            }
            br.close();

            BufferedReader br2 = new BufferedReader(new FileReader(MainMonthly.path + "\\podaci_ts_test_precitor_" + (pred + 1) + "_clusters.csv"));

            String line2 = br2.readLine();
            while (line2 != null) {
                if (!line2.equals("") && line2 != null) {
                    writer.println(line2);
                    writer.flush();
                }
                line2 = br2.readLine();
            }
            br2.close();

            writer.close();

            String pathToFileVar = MainMonthly.path + "\\podaci_ts_all_precitor_" + (pred + 1) + "_variances.csv";
            PrintWriter writerVar = new PrintWriter(new FileWriter(pathToFileVar, true));
            System.out.println(pathToFile);

            BufferedReader brVar = new BufferedReader(new FileReader(MainMonthly.path + "\\podaci_ts_training_precitor_" + (pred + 1) + "_variances.csv"));

            String lineVar = brVar.readLine();
            while (lineVar != null) {
                if (!lineVar.equals("") && lineVar != null) {
                    writerVar.println(lineVar);
                    writerVar.flush();
                }
                lineVar = brVar.readLine();
            }
            brVar.close();

//            BufferedReader brVar2 = new BufferedReader(new FileReader(MainMonthly.path + "\\podaci_ts_test_precitor_" + (pred + 1) + "_variances.csv"));
//
//            String lineVar2 = brVar2.readLine();
//            while (lineVar2 != null) {
//                if (!lineVar2.equals("") && lineVar2 != null) {
//                    writerVar.println(line2);
//                    writerVar.flush();
//                }
//                lineVar2 = brVar2.readLine();
//            }
//            brVar2.close();
            writerVar.close();
        }
    }

    public static void stackTrainingAndTestingResultsEdges() throws FileNotFoundException, UnsupportedEncodingException, IOException {
        ArrayList<ArrayList<String>> files = new ArrayList<>();
        String pathToFile = MainEdgeMonthly.path + "\\podaci_ts_all_clusters.csv";
        PrintWriter writer = new PrintWriter(new FileWriter(pathToFile, true));
        System.out.println(pathToFile);

        BufferedReader br = new BufferedReader(new FileReader(MainEdgeMonthly.path + "\\podaci_ts_training_clusters.csv"));

        String line = br.readLine();
        while (line != null) {
            if (!line.equals("") && line != null) {
                writer.println(line);
                writer.flush();
            }
            line = br.readLine();
        }
        br.close();

        BufferedReader br2 = new BufferedReader(new FileReader(MainEdgeMonthly.path + "\\podaci_ts_test_clusters.csv"));

        String line2 = br2.readLine();
        while (line2 != null) {
            if (!line2.equals("") && line2 != null) {
                writer.println(line2);
                writer.flush();
            }
            line2 = br2.readLine();
        }
        br2.close();

        writer.close();

        String pathToFileVar = MainEdgeMonthly.path + "\\podaci_ts_all_variances.csv";
        PrintWriter writerVar = new PrintWriter(new FileWriter(pathToFileVar, true));
        System.out.println(pathToFileVar);

        BufferedReader brVar = new BufferedReader(new FileReader(MainEdgeMonthly.path + "\\podaci_ts_training_variances.csv"));

        String lineVar = brVar.readLine();
        while (lineVar != null) {
            if (!lineVar.equals("") && lineVar != null) {
                writerVar.println(lineVar);
                writerVar.flush();
            }
            lineVar = brVar.readLine();
        }
        brVar.close();

//            BufferedReader brVar2 = new BufferedReader(new FileReader(MainMonthly.path + "\\podaci_ts_test_precitor_" + (pred + 1) + "_variances.csv"));
//
//            String lineVar2 = brVar2.readLine();
//            while (lineVar2 != null) {
//                if (!lineVar2.equals("") && lineVar2 != null) {
//                    writerVar.println(line2);
//                    writerVar.flush();
//                }
//                lineVar2 = brVar2.readLine();
//            }
//            brVar2.close();
        writerVar.close();
    }
}
